/**
 * 
 */
package edu.sjtu.se.prophet.io.gson;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;

import edu.sjtu.se.prophet.graph.Graph;

/**
 * @author willard
 * 
 */
public class GraphListDeserializer implements JsonDeserializer<List<Graph>> {

    @Override
    public List<Graph> deserialize(JsonElement json, Type type,
            JsonDeserializationContext context) throws JsonParseException {
        JsonArray array = json.getAsJsonArray();
        List<Graph> graphs = new ArrayList<Graph>();
        for (int i = 0; i < array.size(); i++) {
            graphs.add((Graph) context.deserialize(array.get(i), Graph.class));
        }
        return graphs;
    }

}
